

<template>
  <div>
    <h1>当前求和为:{{sum}} </h1>
    <h1>放大十倍求和数:{{bigSum}} </h1>
    <h1>学校名称:{{school}} </h1>
    <h1>科目名称:{{subject}} </h1>
    <select v-model="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment(n)">+</button>
    <button @click="decrement(n)">-</button>
    <button @click="incrementIfOdd(n)">当前求和为奇数再加</button>
    <button @click="incrementAsync(n)">等一等再加</button>
  </div>
</template>

<script >
import { mapState,mapGetters,mapActions,mapMutations } from 'vuex'
export default {
  name: 'Count',
  data() {
    return {
      //用户选择的数据
      n: 1,
    }
  },
  //通过计算属性获取state中的数据
  computed: {

    //使用模块化编程时 需在mapState中传入模块名
    ...mapState('CountAbout',{sum:'sum',school:'school',subject:'subject'}),

    ...mapGetters('CountAbout',{bigSum:'bigSum'}),
  },
  methods: {
    // 使用模块化编程时 需在mapMutations中传入模块名
    ...mapMutations('CountAbout',{increment:'JIA',decrement:'JIAN'}),

    ...mapActions('CountAbout',{incrementIfOdd:'incrementIfOdd',incrementAsync:'incrementAsync'}),

  }
}

</script>
<style scoped>
 button{
   margin-left: 5px;
 }
</style>